package cn.itrip.common;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisUtil {
	private static SqlSessionFactory factory;

	public static final int Order_Status_Wait_To_Pay=0;
	public static final int Order_Status_Cancled=1;
	public static final int Order_Status_Paid =2;
	public static final int Order_Status_Consumed=3;
	public static final int Order_Status_Commented=4;

	public  static final int Book_Type_WEB=0;
	public static  final int Book_Type_Phone=1;
	public static final int Book_Type_Others=2;

	public static final int isNeedInvoice_YES=1;
	public static final int isNeedInvoice_NO=0;

	public static final int invoiceType_Personal=0;
	public static final int invoiceType_Company=1;

	public static final int payType_ALIPAY=1;
	public static final int payType_WECHAT=2;
	public static final int payType_CASH=3;

	static{
		
		//1导入mybatis-config.xml配置文件
		
		try {
			InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
			//2创建sqlssessionfactory对象
			factory =new SqlSessionFactoryBuilder().build(is);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
		
		
	}
	
	/**
	 * 3创建sqlSession
	 * @return sqlSession
	 */
			
	public static SqlSession createSqlSession(){

		return factory.openSession(false);
		
	}


	/**
	 * 关闭sqlsession
	 * @param sqlSession
	 */
	public static void closeSqlSession(SqlSession sqlSession){
		if(sqlSession!=null){
			sqlSession.close();
		}
	}
	
}
